;
(function() {

  new Vue({
    el: '#billListIndex',
    data: {
      data: [],
      billPaymentStateData: [{name: '已收',code: 'APE'}, {name: '未收',code: 'WP'}, {name: '部分',code: 'PPE'}],
      billOverTypeData: [{name: '正常',code: 'NM'}, {name: '即将到期',code: 'DU'}, {name: '已逾期',code: 'OD'}],
      billStateData: [{name: '待提交',code: 'WTJ'}, {name: '待收款',code: 'WSK'}, {name: '完结',code: 'FWJ'}],
      billTypeData: [{name: '合同',code: 'C'},{name: '退租',code: 'T'},{name: '意向书',code: 'YX'},{name: '意向书退款',code: 'YXTK'}],
      selectedBillPaymentStateCode: [],
      selectedOverTypeCode: [],
      selectedBillStateCode: [],
      selectedBillTypeCode: [],
      khname: '',
      beginDate:null,
      endDate:null,
      totalPage: 0,
      totalCount: 0,
      currentPage: 1,
      pageCount: ['10'],
      pages: [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],
      bill:{},
      columns: '#', ///DU逾期天数、BT收款时间
      orders1: '#', //DESC降序，ASC升序
      orders2: '#', //DESC降序，ASC升序
      submitPopFlag:false,
      submitBillMes:{},
      project_ids: null,
      tbTitleWidth:{ width: 0 + 'px'},
      tbTotalWidth:{ width: 957 + 'px'},
      tbOperateWidth:123,
      tbTitle:[],
      wzTableTitle: [],
      jdTableTitle:[],
      pzTableTitle:[],
      sortTableTitle:[],
      hasCustomConfig:'N',
      configType:'JD',
      isShowTableType:false,
      isShowTableLayer:false,
      curModule:'ZDZL',
      tableType:'scroll',   //  scroll滑动表  fixed固定表
      isScroll:false,
      showSelflag: false,
      allcheckflag: false,
      printpaytype: null, //pay 收款    print 打印
      selBusinessIds: [],
      permissions: JSON.parse(window.localStorage.getItem('permissions')),
			projectList: [],
			buildingList: [],
			floorList: [],
			unitList: [],
			projectIDs: [],
			projectId: [],
			buildingId: [],
			floorId: [],
			unitId: [],
      isExtenseFlag: false,
      this_month_bill:'',
      groupId:null,
      groupOneData:[],
      groupTwoData:[],
      groupThreeData:[],
      selectedGroupData:[],

      breaksData:[
        {name:'减免本金',code:'A'},
        {name:'减免滞纳金',code:'L'},
      ],
      selectedBreaksCode:[],
      billBpmConfigArr:[],
      sourceType:'',
    },
    filters: {
      billState: function(str) {
        return hlCodeConvert.billPaymentState(str)
      },
      overDay: function(value) {
				if (value == '--') return '--'
        if (value < 0) {
          return days = '逾期' + Math.abs(value) + '天'
        } else {
          return days = parseFloat(value)
        }
      },
      todou: function(num) {
        return num < 10
          ? '0' + num
          : '' + num;
      },
      formatNum:function(item){
        return hlNumberUtil.formatNum(item)
      },
      formatDate: function(time) {
        if (time === undefined) return '--'
        return hlDateUtil.formatUTCDate(time,'yyyy-MM-dd')
      },
      formatUndefined: function(item) {
        if (!item && item != 0) return '--'
        return item
      }
    },
    methods: {
			getFlexElControl (item) {
				if (!item) return 'dy-fx-1';
				var res;
				switch (item){
					case '序':
						res = 'dy-fx-1'
						break;
					case '收款时间':
						res = 'dy-fx-3'
						break;
					case '距到期天数':
						res = 'dy-fx-3'
						break;
					default:
						res = 'dy-fx-2'
						break;
				}
				return res
			},
			//获取账单提交流程开启
			getbillflow () {
				hlhttp.get({
				  url: 'configure/bill_bpm_config/dict',
				  success: res=> {
						if (res.open_flag == 'Y') {
							this.billStateData = [{name: '待提交',code: 'WTJ'},{name: '审批中',code: 'BWA'},{name: '审批拒绝',code: 'BRJ'}, {name: '待收款',code: 'WSK'}, {name: '完结',code: 'FWJ'}]
						}			
				  }
				})
			},
			
      selectBillMenu(){
        this.currentPage = 1
        this.getData()
      },
			//结转跳转
			 toCarryOverUrl (item) {
				 hlUrlUtil.goTo('carryOver', {id: item.id, aid: item.contractId, ddtab: true, page: 'billList'}, true)
			 },
        //获取本月数据
      getThisMonthData(){
        this.this_month_bill = 'TMB'
        this.getData()

        var date = new Date()
        date.setDate(1)
        var month = parseInt(date.getMonth() + 1)
        var day = date.getDate()
        if (month < 10) month = '0' + month
        if (day < 10) day = '0' + day

        this.beginDate = date.getFullYear() + '-' + month + '-' + day
        this.setEnd()
      },
      setEnd(){
        var date = new Date()
        var year = date.getFullYear()
        var month = date.getMonth() + 1
        month = month < 10 ? '0' + month : month
        var day = new Date(year, month, 0)

        this.endDate = year + '-' + month + '-' + day.getDate()
      },
      resetTabbar(){
        this.selectedBillPaymentStateCode = []
        this.selectedOverTypeCode = []
        this.selectedBillStateCode = []
        this.selectedBillTypeCode = []
        this.selectedBreaksCode = []
        this.currentPage = 1

        this.getData()
      },
      //批量打印
      showprintSel () {
        this.selBusinessIds = []
        this.showSelflag = !this.showSelflag;
        if (this.printpaytype == 'pay') {
          this.showSelflag = true
        }
        this.printpaytype = 'print'
        this.allcheckflag = false;
        this.bill.bills.map(item => {
          item.flag = false
        })
      },
      //批量打印
      printAll () {
        let payArr = hlArrayUtil.removeRepeat(this.selBusinessIds, 'bill_id');
        if (!payArr.length) {
          hl.toast('请选择账单')
          return
        }
        if (!payArr.length) {
          hl.toast('请选择账单')
          return
        }
        hllayer.confirm1('是否确认批量打印当前选择账单?', () => {
          hlhttp.post({
            url: 'bill/bill_printing_pdfs',
            data: {printing_datas: JSON.stringify(payArr)},
            success: (res) => {
              if (res.url) {
                hl.toast('操作成功')
                $.previewPDF(res.url)
                this.showSelflag = false
                this.allcheckflag = false;
              }
            }
          })
        })
      },
      //批量收款
      showallSel () {
        this.showSelflag = !this.showSelflag;
        if (this.printpaytype == 'print') {
          this.showSelflag = true
        }
        this.printpaytype = 'pay'
        this.allcheckflag = false;
        this.bill.bills.map(item => {
          item.flag = false
        })
      },
      //全选全不选
      selAll () {
        if (!this.allcheckflag) {
          this.allcheckflag = true;
          this.bill.bills.map(item => {
            item.flag = true;
            if (this.printpaytype == 'print') {
              if (item.contractId) {
                this.selBusinessIds.push({
                  project_id: item.projectId,
                  bill_id: item.id,
                  contract_id: item.contractId
                })
              }
            }
          })
          return
        }
        if (this.allcheckflag) {
          this.allcheckflag = false;
          this.bill.bills.map(item => {
            item.flag = false;
          })
          let newArr = [];
          this.selBusinessIds.map((item, index) => {
            let newFlag = false;
            this.bill.bills.map((item0, index0) => {
              if (item.bill_id == item0.id) {
                newFlag = true;
              }
            })
            if (!newFlag) {
              newArr.push(item)
            }
          })
          this.selBusinessIds = JSON.parse(JSON.stringify(newArr))
          return
        }
      },
      //单选操作
      sgelection (i) {
        this.bill.bills[i].flag = !this.bill.bills[i].flag;
        let flag = false;
        this.bill.bills.map(item => {
          if (!item.flag) {
            flag = true
          }
        })
        if (flag) {
          this.allcheckflag = false;
        }
        if (!flag) {
          this.allcheckflag = true;
        }
        if (this.printpaytype == 'print') {
          if (this.bill.bills[i].flag) {
            if (this.bill.bills[i].contractId) {
              this.selBusinessIds.push({
                project_id: this.bill.bills[i].projectId,
                bill_id: this.bill.bills[i].id,
                contract_id: this.bill.bills[i].contractId
              })
            }
            return
          }
          if (!this.bill.bills[i].flag) {
            this.selBusinessIds.map((item, index) => {
              if (item.bill_id == this.bill.bills[i].id) {
                this.selBusinessIds.splice(index, 1)
              }
            })
          }
        }
      },
      listitemFlag () {
        let count = 0;
        this.bill.bills.map(item0 => {
          this.selBusinessIds.map(item1 => {
            if (item0.id == item1.bill_id) {
              count ++
              item0.flag = true;
            }
          })
        })
        if (count >= this.bill.bills.length) {
          this.allcheckflag = true;
        }
      },
      search(){
        this.currentPage = 1
        this.getData()
      },
      getData() {
        var self = this,projectIDsIn = [],projectIDs = [];
        var name = window.localStorage.getItem('cname')
        if (name) { self.khname = name }

        var data = {
          zlf_name: self.khname.trim() || '#',
					project_ids: self.projectIDs.toString() || '#',
          project_id: self.projectId.length ? self.projectId[0] : '#',
          group_id: self.groupId || '#',
          building_id: self.buildingId.length ? self.buildingId[0] : '#',
          floor_id: self.floorId.length ? self.floorId[0] : '#',
          unit_id: self.unitId.length ? self.unitId[0] : '#',
          begin_date: self.beginDate || '#',
          end_date: self.endDate || '#',
          this_month_bill: self.this_month_bill || '#',
          payment_state: self.selectedBillPaymentStateCode.length ? self.selectedBillPaymentStateCode.join() : '#', //支付状态
          overdue_state: self.selectedOverTypeCode.length ? self.selectedOverTypeCode.join() : '#', //逾期状态
          bill_state: self.selectedBillStateCode.length ? self.selectedBillStateCode.join() : '#', //账单状态，
          bill_type:self.selectedBillTypeCode.length ? self.selectedBillTypeCode.join() : '#',
          derate_type:self.selectedBreaksCode.length ? self.selectedBreaksCode.join() : '#',
          page: self.currentPage, //请求页
          pageCount: self.pageCount[0], //每页数量
          columns:self.columns,
          orders: self.columns == 'DU' ? this.orders1 : this.orders2
        }

        hlhttp.get({
          url: 'bills/_search',
          data: data,
          success: function(res) {
            res.bills.map(item => {
              item.flag = false
              item.billPeriod = (hlDateUtil.formatUTCDate(item.billBeginDate, 'yyyy-MM-dd') + '至' + hlDateUtil.formatUTCDate(item.billEndDate, 'yyyy-MM-dd')) || '--'
            })

            self.bill = res
            self.totalCount = res.totalCount
            self.totalPage = res.totalPage
            self.data = res.bills;
            self.listitemFlag()
            loginPrem.loginList()

            if (name) { window.localStorage.removeItem('cname') }

          }
        })
      },
      sort (item,index) {
        const sortName = item.name;
        if(sortName == '收款时间') this.columns = 'BT';
        if(sortName == '距到期天数') this.columns = 'DU';
        if (this.columns == 'DU') {
          $('.du-icon').removeClass('icon-Gm-sort-default')
          $('.bt-icon').addClass('icon-Gm-sort-default').removeClass('icon-Gm-sort-ascending icon-Gm-sort-descending')
          if (this.orders1 == 'ASC') {
            this.orders1 = 'DESC'
            $('.du-icon').removeClass('icon-Gm-sort-ascending').addClass('icon-Gm-sort-descending')
          } else {
            this.orders1 = 'ASC'
            $('.du-icon').removeClass('icon-Gm-sort-descending').addClass('icon-Gm-sort-ascending')
          }
        }
        if (this.columns == 'BT') {
          $('.bt-icon').removeClass('icon-Gm-sort-default')
          $('.du-icon').addClass('icon-Gm-sort-default').removeClass('icon-Gm-sort-ascending icon-Gm-sort-descending')
          if (this.orders2 == 'ASC') {
            this.orders2 = 'DESC'
            $('.bt-icon').removeClass('icon-Gm-sort-ascending').addClass('icon-Gm-sort-descending')
          } else {
            this.orders2 = 'ASC'
            $('.bt-icon').removeClass('icon-Gm-sort-descending').addClass('icon-Gm-sort-ascending')
          }
        }
        this.getData(1);
      },
      getDateTime: function(arr) {
        const self = this;
				self.pageCount = [arr[0].code]
        self.currentPage = 1
        self.getData()
      },
      resetData: function() {
        this.khname = '';
        this.beginDate = null
        this.endDate = null
				this.projectId = []
        this.groupId = null
				this.buildingId = []
				this.floorId = []
				this.unitId = []
        this.this_month_bill = ''
				this.buildingList = []
				this.floorList = []
				this.unitList = []
        this.selectedGroupData = []
        this.currentPage = 1

        this.getData()
      },
      // 提交账单
      submitBill:function(contractId,billId,amountReceived,lateFeeReceive,lateFeePayed,state,intentId,sourceType){
        this.sourceType = sourceType
        var self = this;
        if (contractId) {
          hlhttp.get({
            url:'contract',
            data:{id:contractId},
            success:function(data){
              self.submitBillMes = {
                'billId':billId,
                'zlfCompany':data.zlfCompany,
                'amountReceived':0,
                'lateFeeReceived':0,
              }
              hlhttp.get({
                url:'bill,expenses,transactions',
                data:{bill_id:billId},
                success:function(_data){
                  self.submitBillMes['expenses'] = _data.expenses
                  self.submitBillMes['deadlineDate'] = _data.deadlineDate
                  self.submitBillMes['beginDate'] = _data.beginDate
                  self.submitBillMes['endDate'] = _data.endDate
									self.submitBillMes['refundTPay'] = _data.refundTPay
									self.submitBillMes['refundCarryover'] = _data.refundCarryover
									self.submitBillMes['amountCarryover'] = _data.amountCarryover
									self.submitBillMes['lateFeeTPay'] = _data.lateFeeTPay
                  self.submitPopFlag = true;
                  
                  self.submitBillMes.amountTPay = _data.amountTPay
                }
              })
            }
          })
        }
        if (state == 'YX' || state == 'YXTK') {
          hlhttp.get({
            url:'contract/intent',
            data:{id:intentId},
            success:function(data){
              self.submitBillMes = {
                'billId':billId,
                'zlfCompany':data.zlfInfo.zlfName,
                'amountReceived':0,
                'lateFeeReceived':0,
              }
              hlhttp.get({
                url:'bill,expenses,transactions',
                data:{bill_id:billId},
                success:function(_data){
                  self.submitBillMes['expenses'] = _data.expenses
                  self.submitBillMes['deadlineDate'] = _data.deadlineDate
                  self.submitBillMes['beginDate'] = _data.beginDate
                  self.submitBillMes['endDate'] = _data.endDate
                  self.submitBillMes['refundTPay'] = _data.refundTPay
                  self.submitBillMes['refundCarryover'] = _data.refundCarryover
                  self.submitBillMes['amountCarryover'] = _data.amountCarryover
                  self.submitBillMes['lateFeeTPay'] = _data.lateFeeTPay
                  self.submitPopFlag = true;
                  
                  self.submitBillMes.amountTPay = _data.amountTPay
                }
              })
            }
          })
        }
      },
      closeBillPop:function(){
        this.submitPopFlag = false;
      },
      getBillBpmValue(){
        hlhttp.get({
          url:'configure/bill_bpm_config/dict',
          success:res =>{
            if (res.open_flag == 'N') return
            res.dict_property = JSON.parse(res.dict_property)
            this.billBpmConfigArr = res.dict_property.billBpmValue
          }
        })
      },
      // 确认提交账单
      confirmSubmitBill:function(){
        var self = this;
        var expenseIdsArr = [],amountDerateArr = [], lateFeeDerateArr = [],latefeesArr = [];
        self.submitBillMes.expenses.map(function(item,index){
          expenseIdsArr.push(item.id);
          amountDerateArr.push(item.amountDerate);
          lateFeeDerateArr.push(item.lateFeeDerate);
          latefeesArr.push(item.lateFeeTPay)
        })
        let arr = []
        this.billBpmConfigArr.map(item => {
          if (item.openFlag == 'Y' && item.dictCode == "BPM_JEWBH" && this.sourceType != 'C') {
            arr.push(item.dictCode)
          }
          if (item.openFlag == 'Y' && item.dictCode == "BPM_LSZD" && this.sourceType == 'C') {
            arr.push(item.dictCode)
          }
        })
        hlhttp.put({
          url:'bill',
          data:{
            bill_id:self.submitBillMes.billId,
            expense_ids:'#',
            amountDerate:'#',
            lateFeeDerate:'#',
            late_fees:'#',
            is_submit: 'Y',
            bill_bpm_value:arr + '' || '#',
          },
          success:function(data){
            self.submitPopFlag = false;
            self.currentPage = 1
            self.getData();
          }
        })

      },
      // 对应表头字段表宽度值
      getThWidth(val) {
        var res = 70 ;
        switch (val) {
          case '序':
            res = '40'
            break;
          case '客户':
            res = '90'
            break;
          case '合同名称':
            res = '90'
            break;
          case '项目名':
            res = '80'
            break;
          case '应收金额(元)':
            res = '90'
            break;
          case '已收金额(元)':
            res = '90'
            break;
          case '减免金额(元)':
            res = '90'
            break;
          case '未收余额(元)':
            res = '90'
            break;
          case '账单状态':
            res = '70'
            break;
          case '业务状态':
            res = '70'
            break;
          case '收款时间':
            res = '92'
            break;
          case '距到期天数':
            res = '104'
            break;
          case '账单类型':
            res = '70'
            break;
          default:
        }
        return res;
      },
      // 对应表头字段是否排序
      getThSort(val) {
        var res;
        switch (val) {
          case '序':
            res = 'N'
            break;
          case '客户':
            res = 'N'
            break;
          case '合同名称':
            res = 'N'
            break;
          case '项目名':
            res = 'N'
            break;
          case '应收金额(元)':
            res = 'N'
            break;
          case '已收金额(元)':
            res = 'N'
            break;
          case '减免金额(元)':
            res = 'N'
            break;
          case '未收余额(元)':
            res = 'N'
            break;
          case '账单状态':
            res = 'N'
            break;
          case '业务状态':
            res = 'N'
            break;
          case '收款时间':
            res = 'Y'
            break;
          case '距到期天数':
            res = 'Y'
            break;
          case '账单类型':
            res = 'Y'
            break;
          default:
        }
        return res;
      },
      // 获取自定义表头配置
      getHeadConfig() {
        var self = this;
        hlhttp.get({
          url: 'contract/column_header_config',
          data: { 'module': self.curModule },
          success: function(data) {
            var wzTableTitle = [];
            data.systemConfig.forEach((el,i) => {
              var obj = {};
              el['width'] = self.getThWidth(el.name)
              el['isSort'] = self.getThSort(el.name)
              obj = JSON.parse(JSON.stringify(el))
              obj['isShow'] = 'Y'
              wzTableTitle.push(obj)
            })

            data.customConfig.forEach(el => {
              var obj = {};
              el['width'] = self.getThWidth(el.name)
              el['isSort'] = self.getThSort(el.name)
              el['isActive'] = 'N'
            })

            self.wzTableTitle = wzTableTitle;
            self.jdTableTitle = data.systemConfig;
            self.pzTableTitle = data.customConfig;
            self.sortTableTitle = JSON.parse(JSON.stringify(data.customConfig))
            self.hasCustomConfig = data.hasCustomConfig;
            self.configType = data.configType;
            self.refreshTableData()
          }
        })
      },
      // 计算表格标题栏宽度
      calTbTitleWidth(){
        var self = this,width = 0;
        self.tbTitle.forEach(el => {
          if(el.isShow == 'Y') width += Number(el.width);
        })
        return width
      },
      // 计算表格外容器宽度
      calTbWidth(){
        var width = this.calTbTitleWidth() + this.tbOperateWidth;
        return width > 957 ? 957 : width
      },
      // 刷新当前表格
      refreshTableData(){
        var self = this;

        if(self.configType == 'JD') self.tbTitle = self.jdTableTitle;
        if(self.configType == 'WZ') self.tbTitle = self.wzTableTitle;
        if(self.configType == 'PZ') self.tbTitle = self.pzTableTitle;
        const tbTitleWidth = self.calTbTitleWidth();
        self.tbTitleWidth = { width:tbTitleWidth < 839 ? '100%' : tbTitleWidth + 'px' };
        self.tbTotalWidth = { width:self.calTbWidth() + 'px'};
        // 根据表格title总宽度 来判断当前显示哪种表格类型
        if(tbTitleWidth > 833) self.tableType = 'scroll';
        if(tbTitleWidth <= 833) self.tableType = 'fixed';
      },
      showScroll(){
        this.isScroll = true;
      },
      hideScroll(){
        this.isScroll = false;
      },
      // 保存当前所选表格类型
      saveTableType(type){
        var self = this;
        hlhttp.post({
          url:'contract/column_header_select',
          data:{ 'module': self.curModule , 'config_type':type },
          success:function(data){
            self.refreshTableData()
          }
        })
      },
      // 保存当前表头
      saveTableTitle(data,isLayer){
        var self = this;
        function dataWrap(data){
          var res = [];
          data.forEach((el,i) => {
            res.push({
              'id':el.id,
              'name':el.name,
              'display_name':el.displayName ? el.displayName : '#',
              'value':el.value,
              'is_show':el.isShow,
              'seq':(i + 1).toString()
            })
          })
          return res;
        }

        hlhttp.post({
          url:'contract/column_header_config',
          data:{'module': self.curModule ,'has_custom_config':self.hasCustomConfig,'custom_config':JSON.stringify(dataWrap(data))},
          success:function(res){
            if(isLayer){
              hl.toast('保存成功')
              self.pzTableTitle = JSON.parse(JSON.stringify(data));
              self.isShowTableLayer = false;
              self.refreshTableData()
            }
          }
        })
      },
      selectTableType(type){
        var self = this;
        if(type == 'JD'){
          self.configType = 'JD'
          self.saveTableType(type);
          return ;
        }
        if(type == 'WZ'){
          self.configType = 'WZ'
          self.saveTableType(type);
          return ;
        }
        if(type == 'PZ'){
          self.configType = 'PZ'
          self.saveTableType(type);
          // 如果当前自定义表没有配置过 则强制保存完整表头数据
          if(self.hasCustomConfig == 'N') self.saveTableTitle(self.wzTableTitle)
          return ;
        }
      },
      showTableTypeComponents(){
        this.isShowTableType = true;
      },
      hideTableTypeComponents(){
        this.isShowTableType = false;
      },
      showTableLayer(){
        this.isShowTableLayer = true;
      },
      closeTableLayer(){
        this.isShowTableLayer = false;
      },
      showhighLightTitleItem(el,i){
        var self = this;
        this.$set(self.sortTableTitle[i],'isActive','Y')
      },
      removehighLightTitleItem(el,i){
        var self = this;
        this.$set(self.sortTableTitle[i],'isActive','N')
      },
      selectedTitleItem(el,i){
        var self = this;
        this.$set(self.sortTableTitle[i],'isShow','Y')
      },
      cancelSelectedTitleItem(el,i){
        var self = this;
        this.$set(self.sortTableTitle[i],'isShow','N')
      },
      // 确定提交自定义表格
      confirmSubmitTable(){
        var self = this;
        self.saveTableTitle(self.sortTableTitle,true)
      },
      // 初始化拖动排序
      initSortable(){
        const self = this;
        const el = document.getElementById('sortableTable');
        Sortable.create(el,{
          draggable:'ul',
          onEnd(evt){
            const beginIndex = evt.oldIndex;
            const endIndex = evt.newIndex;
            const newArr = JSON.parse(JSON.stringify(self.sortTableTitle));
            newArr.splice(endIndex,0,newArr.splice(beginIndex,1)[0])
            self.sortTableTitle = [];
            self.$nextTick(() => {
              self.sortTableTitle = newArr
            })
          }
        })
      },
      createBill () {
        hlUrlUtil.goTo('createBill',{'page': 'billList', ddtab:true})
      },

			openSearch: function() {
			  if (this.isExtenseFlag == true) {
			    this.isExtenseFlag = false;
					this.projectId = []
					this.buildingId = []
					this.floorId = []
					this.unitId = []
					this.buildingList = []
					this.floorList = []
					this.unitList = []
			    return false;
			  }
			  if (this.isExtenseFlag == false) {
			    this.isExtenseFlag = true;
			    return false;
			  }
			},
			//获取项目
			getprojectData () {
        const self  = this

			  hlhttp.get({
			    url: 'user/projects',
			    success: (res) => {
						res = hlArrayUtil.removeRepeat(res, 'projectId')
						self.projectList = hlArrayUtil.replaceData(res, [{key: 'projectName', rKey: 'name'}, {key: 'projectId', rKey: 'code'}]);
						self.projectList.map(item => this.projectIDs.push(item.projectId))
						self.getData()
			    }
			  })
			},
      // 获取一级组合数据
      getGroupPrimaryData(data){
        const self = this
        self.projectId = [data[0].code]
        self.groupId = null
        self.buildingId = []
        self.floorId = []
        self.unitId = []
        self.buildingList = []
        self.floorList = []
        self.unitList = []
        self.selectedGroupData = []
        self.getGroupData().then(data => {
          self.groupOneData = hlArrayUtil.replaceData( data, [{key: 'id', rKey: 'code'}] );
        })
        self.getBuildingData()
      },
      // 选取一级组合数据
      selectOneGroup(res){
        const self = this
        this.groupId = res['cur']['code']
        this.getGroupData().then(data => {
          self.groupTwoData = hlArrayUtil.replaceData( data, [{key: 'id', rKey: 'code'}] )
          self.getBuildingData()
        })
      },
      // 选取二级组合数据
      selectTwoGroup(res){
        const self = this
        this.groupId = res['cur']['code']
        this.getGroupData().then(data => {
          self.groupThreeData = hlArrayUtil.replaceData( data, [{key: 'id', rKey: 'code'}] )
          self.getBuildingData()
        })
      },
      // 选取三级组合数据
      selectThreeGroup(res){
        this.groupId = res['cur']['code']
      },
      getGroupData(){
        const self = this

        return new Promise(resolve => {
          hlhttp.get({
            url:'project/grouping_info/_subclass',
            data:{'project_id':self.projectId[0] , 'grouping_id':self.groupId || '#' },
            success:function(data){
              resolve(data)
            }
          })
        })
      },
      //获取楼宇
      getBuildingData () {
        const self = this

        hlhttp.get({
          url: 'project/grouping/_building',
          data: { project_id: self.projectId.length ? self.projectId[0] : '#'  , grouping_id:self.groupId || '#'},
          success: (res) => {
            this.buildingList = hlArrayUtil.replaceData(res, [{key: 'buildingId', rKey: 'code'}]);
          }
        })
      },
			//获取楼层
			getfloorData () {
			  hlhttp.get({
			    url: 'building/floors',
			    data: {project_id: this.projectId[0], building_id: this.buildingId[0]},
			    success: (res) => {
			      this.floorList = hlArrayUtil.replaceData(res, [{key: 'floorName', rKey: 'name'}, {key: 'floorId', rKey: 'code'}]);
			    }
			  })
			},
			//获取单元
			getunitData () {
			  hlhttp.get({
			    url: 'floor/units',
			    data: {project_id: this.projectId[0], building_id: this.buildingId[0], floor_id: this.floorId[0]},
			    success: (res) => {
			      this.unitList = hlArrayUtil.replaceData(res, [{key: 'unitName', rKey: 'name'}, {key: 'unitId', rKey: 'code'}]);
			    }
			  })
			},
			//点击楼宇获得 id
			getbuildingId (arr) {
			  this.buildingId = [arr[0].code];
			  this.getfloorData()
			  this.floorId = [];
			  this.unitId = [];
			},
			//点击楼层获得 id
			getfloorId (arr) {
			  this.floorId = [arr[0].code];
			  this.getunitData()
			  this.unitId = [];
			},
			// 点击单元获得 id
			getunitId (arr) {
			  this.unitId = [arr[0].code];
			},
    },
    mounted: function() {
      var _this = this;
      _this.initSortable()
      this.getbillflow()
      this.getBillBpmValue()
      hlSelectUi(true)

			this.getprojectData()
			this.getHeadConfig()

			if (hlUrlUtil.GetQueryString('NAVPOSITION1')) {
        _this.selectedBillPaymentStateCode = [hlUrlUtil.GetQueryString('NAVPOSITION2')]
        _this.selectedOverTypeCode = [hlUrlUtil.GetQueryString('NAVPOSITION1')]
			}

			if (hlUrlUtil.GetQueryString('payment_state')) {
			  if (hlUrlUtil.GetQueryString('payment_state') == '#') {
			    _this.selectedBillPaymentStateCode = [hlUrlUtil.GetQueryString('payment_state')]
			  }
			  if (hlUrlUtil.GetQueryString('payment_state') != '#') {
			    _this.selectedBillPaymentStateCode = hlUrlUtil.GetQueryString('payment_state').split(',')
			  }
			}

			if (hlUrlUtil.GetQueryString('overdue_state')) {
			  if (hlUrlUtil.GetQueryString('overdue_state') == '#') {
			    _this.selectedOverTypeCode = [hlUrlUtil.GetQueryString('overdue_state')]
			  }
			  if (hlUrlUtil.GetQueryString('overdue_state') != '#') {
			    _this.selectedOverTypeCode = hlUrlUtil.GetQueryString('overdue_state').split(',')
			  }
			}

			if (hlUrlUtil.GetQueryString('bill_state')) {
			  if (hlUrlUtil.GetQueryString('bill_state') == '#') {
			    _this.selectedBillStateCode = [hlUrlUtil.GetQueryString('bill_state')]
			  }
			  if (hlUrlUtil.GetQueryString('bill_state') != '#') {
			    _this.selectedBillStateCode = hlUrlUtil.GetQueryString('bill_state').split(',')
			  }
			}

			if (hlUrlUtil.GetQueryString('begin_date')) {
			  if (hlUrlUtil.GetQueryString('begin_date') != '#') {
			    beginDate.setAttribute('value', hlUrlUtil.GetQueryString('begin_date'))
			  }
			}
			if (hlUrlUtil.GetQueryString('end_date')) {
			  if (hlUrlUtil.GetQueryString('end_date') != '#') {
			    endDate.setAttribute('value', hlUrlUtil.GetQueryString('end_date'))
			  }
			}
			if (hlUrlUtil.GetQueryString('zlf_name')) {
			  if (hlUrlUtil.GetQueryString('zlf_name') != '#') {
			    if(window.sessionStorage.getItem('zlf_name')){
			      _this.khname = window.sessionStorage.getItem('zlf_name')
			    }
			  }
			}


    }

  })

}())
